﻿using Infrastructure.Utility;
using System;
/// <summary>
/// BasePage 的摘要说明
/// </summary>
using System.Collections.Generic;
public class BasePage : System.Web.UI.Page
{
    protected const int PAGE_SIZE = 10;//每页10行

    protected int Index
    {
        get { return ViewState["page_index"] == null ? 1 : (int)ViewState["page_index"]; }
        set { ViewState["page_index"] = value; }
    }
    protected int TotalSize
    {
        get { return ViewState["total_pages"] == null ? 0 : (int)ViewState["total_pages"]; }
        set { ViewState["total_pages"] = value; }
    }
    protected Dictionary<string, object> Entity
    {
        get
        {
            if (ViewState["__Entity"] == null) ViewState["__Entity"] = new Dictionary<string, object>();
            return ViewState["__Entity"] as Dictionary<string, object>;
        }
    }
    protected T Data<T>(string p)
    {
        return Entity.ContainsKey(p) ? Entity[p].To<T>() : default(T);
    }

    protected string Data(string p)
    {
        return Entity.ContainsKey(p) ? Convert.ToString(Entity[p]) : string.Empty;
    }
    /// <summary>
    /// 返回相对路径。避免暴露主机目录结构。
    /// </summary>
    /// <param name="p"></param>
    /// <returns></returns>
    public string GetSitePath(string p)
    {
        var root = Server.MapPath("~");
        return p.Replace(root, string.Empty).Replace("\\", "/");
    }
}